﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache">  <!-- HTTP 1.1 -->
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">  <!-- HTTP 1.0 -->
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/> <!--优先级：极速模式，兼容模式，IE模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>扬州房产测绘业务管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../../libs/jeasyui-181/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../../libs/jeasyui-181/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../../libs/jeasyui-181/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../../../css/common.css">
    <script type="text/javascript" src="../../../libs/jeasyui-181/jquery.min.js"></script>
    <script type="text/javascript" src="../../../libs/jeasyui-181/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../../libs/thUtil.js"></script>
    <script type="text/javascript">

        var mainGrid = new UserContol();

        $(function () {
            if (UrlParm.hasParm('text')) {
                $('h1').html(UrlParm.parm('text'));
            }
            $('#bind_Link').linkbutton({onClick: ajax.bind});
            mygrid.init();
        });

        var ajax = {
            getList: function (param, success) {
                Network.connect(window.api.materialTreeGrid, 'POST', param, function (res) {
                    if (res.code === ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            bind: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 0) {
                    Tools.alert('请选择需要绑定的数据。');
                    return;
                }
                dlg = top.$.hDialog({
                    href: window.router.bindFlowForm + '?n=' + Math.random(),
                    title: '绑定流程',
                    width: 700,
                    height: 360,
                    onLoad: function () {
                        top.$("#flowId").val(rows[0].flowId);
                        top.$("#bindId").val(rows[0].bindId);
                        //流程类型
                        ajax.getDeployedModel(function (arr) {
                            top.$("#deploymentId").combobox('loadData', arr);
                        });
                    },
                    submit: function () {
                        var isValid = top.$('#form').form("validate");
                        if (isValid) {

                            var formData = top.$("#form").serializeJson();
                            console.log(formData);
                            Network.connect(window.api.saveMaterialBindInfo, 'POST', formData, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show('绑定成功');
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            getDeployedModel: function (methods) {
                //流程类型
                Network.connect(window.api.getDeployedModel, "POST", {}, function (res) {
                    if (res.code === ResponseCode.OK) {
                        methods(res.data.rows);
                    }
                });
            },
            resort: function () {
                Tools.confirm('是否确定重新整理数据？', function (result) {
                    if (result) {
                        Network.connect(window.api.groupReSort, 'POST', {}, function (res) {
                            if (res.code == ResponseCode.OK) {
                                Tools.show('重新整理成功');
                                mygrid.reload();
                            }
                        });
                    }
                });
            }
        }

        var mygrid = {
            init: function () {
                $("#mainGrid").treegrid({
                    fit: true,
                    toolbar: '#toolbar',
                    fitColumns: false,
                    width: $(window).width() - 22,
                    height: $(window).height() - 110,
                    rownumbers: false,
                    pagination: false,
                    idField: 'flowId',
                    treeField: 'flowId',
                    columns: [[
                        {field: 'flowId', title: '流程模型ID', halign: 'center', align: 'center', width: 120},
                        {field: 'flowName', title: '流程模型', halign: 'center', align: 'center', width: 120},
                        {field: 'name', title: '材料名称', halign: 'center', align: 'left', width: 350},
                        {field: 'no', title: '材料序号', halign: 'center', align: 'center', width: 90, sortable: true}
                    ]],
                    loader: function (param, success, error) {
                        $('#mainGrid').treegrid('clearSelections');
                        ajax.getList(param, success);
                    }
                });
                $(window).resize(function () {
                    $('#mainGrid').datagrid('resize', {
                        width: $(window).width() - 22,
                        height: $(window).height() - 110
                    })
                });
            },
            reload: function () {
                $('#mainGrid').treegrid('reload');
            },
            selectRow: function () {
                return $('#mainGrid').treegrid('getSelected');
            }
        };

    </script>

</head>
<body>
<div class="container-wrap">
    <div id="toolbar">
        <div class="container-tit">
            <h1></h1>
        </div>
        <div class="sreach fixed">
            <!--<input type="text" class="easyui-textbox" data-options="label:'上级部门:',labelWidth: 80,width:240,"/>
            <a href="#" class="easyui-linkbutton search">查询</a>-->
            <div class="bar-btn">
                <a id="bind_Link" href="#" class="easyui-linkbutton update">绑定模型</a>
            </div>
        </div>
    </div>
    <div id="mainGrid"></div>
</div>
</body>
</html>